﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Controllers;

namespace Web
{
    public partial class AuthedMenu : System.Web.UI.Page
    {
        protected StringBuilder menuSB = new StringBuilder(@"<script>
                d = new dTree('d', 'dtree');
                d.add(0, -1, '授权文档','AuthedList.aspx', '授权文档','mdi');");
        protected IEnumerable<AuthedFilesDTO> docDtoes;
        protected void Page_Load(object sender, EventArgs e)
        {
            ApolloOaDataContext ctx = new ApolloOaDataContext(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
            EmpBasicInfo ebi = Session["ebi"] as EmpBasicInfo;
            docDtoes = ctx.ExecuteQuery<AuthedFilesDTO>(
                    @"SELECT c.Id,c.Name,COUNT(0) cnt
  FROM Files a,FileAuth b,Employee c
  where a.CreatTime>dateadd(m,-1,GETDATE()) and a.Id=b.FileId and b.ToId={0} and b.FromId=c.Id and (c.LeaveDate is null or c.LeaveDate>=GETDATE())
  group by c.Id,c.Name order by c.Name;", ebi.Id).ToList();
            foreach(AuthedFilesDTO af in docDtoes)
            {
                menuSB.AppendFormat("d.add({0},{1},'{2}', '{3}', '{4}', 'mdi');",af.Id,0,af.Name+"("+af.Cnt+")", "AuthedList.aspx?id=" +af.Id,af.Name);
            }
            menuSB.Append(@"d.draw();
            </script>");
        }
    }
}